import { createRouter, createWebHashHistory } from "vue-router";
import HomeView from "../views/HomePage.vue";
import TestView from "@/views/TestView.vue";
import BannerView from "@/views/BannerView.vue";
import LaboratoryOverview from "@/views/LaboratoryOverview.vue";
import TalentTeam from "@/views/TalentTeam.vue";
import ScientificResearch from "@/views/ScientificResearch.vue";
import PersonnelTraining from "@/views/PersonnelTraining.vue";
import PartyAndWork from "@/views/PartyAndWork.vue";
import TalentIntroduction from "@/views/TalentIntroduction.vue";
import CooperationAndExchange from "@/views/CooperationAndExchange.vue";
// 新闻页面
import NewsDetail from "@/views/news/NewsDetail.vue";
import NewsList from "@/views/news/NewsList.vue";
const routes = [
  {
    path: "/",
    component: HomeView,
    redirect: "/homePage",
    meta: {
      title: "实验室首页",
    },
  },
  {
    path: "/homePage",
    name: "homePage",
    component: HomeView,
    meta: {
      title: "实验室首页",
    },
  },
  {
    path: "/laboratoryOverview",
    name: "laboratoryOverview",
    component: LaboratoryOverview,
    meta: {
      title: "实验室概况",
    },
  },
  {
    path: "/talentTeam",
    name: "talentTeam",
    component: TalentTeam,
    meta: {
      title: "人才队伍",
    },
  },
  {
    path: "/scientificResearch",
    name: "scientificResearch",
    component: ScientificResearch,
    meta: {
      title: "科学研究",
    },
  },
  {
    path: "/personnelTraining",
    name: "personnelTraining",
    component: PersonnelTraining,
    meta: {
      title: "人才培养",
    },
  },
  {
    path: "/partyAndWork",
    name: "partyAndWork",
    component: PartyAndWork,
    meta: {
      title: "党群工作",
    },
  },
  {
    path: "/talentIntroduction",
    name: "talentIntroduction",
    component: TalentIntroduction,
    meta: {
      title: "人才引进",
    },
  },
  {
    path: "/cooperationAndExchange",
    name: "cooperationAndExchange",
    component: CooperationAndExchange,
    meta: {
      title: "合作交流",
    },
  },
  {
    path: "/banner",
    name: "banner",
    component: BannerView,
    meta: {
      title: "科研轮播图",
    },
  },
  {
    path: "/test",
    name: "test",
    component: TestView,
    meta: {
      title: "测试页面",
    },
  },
  {
    path: "/news/:id",
    name: "NewsDetail",
    component: NewsDetail,
    props: true,
  },
  {
    path: "/all-news",
    name: "NewsList",
    component: NewsList,
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  if (to.meta.favicon) {
    document.head.innerHTML = `<link rel="icon" href="${to.meta.favicon}">`;
  }
  next();
});

export default router;
